﻿using LibNoise.Builder;
using LibNoise.Renderer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using dto = BloxDTO;

namespace BloxServer2012.WorldGen
{
    public class Chunk
    {
        public dto.BlockType[, ,] blocksSolid;

        public Chunk(int Size = 16, int seed = 1234)
        {
            blocksSolid = new dto.BlockType[Size, Size, Size];
            LibNoise.Primitive.SimplexPerlin mountainTerrain = new LibNoise.Primitive.SimplexPerlin(seed, LibNoise.NoiseQuality.Fast);
            NoiseMap heightMap = new NoiseMap();
            NoiseMapBuilderPlane heightMapBuilder = new NoiseMapBuilderPlane(0f, 15f, 0f, 15f, true);
            heightMapBuilder.SourceModule = mountainTerrain;
            heightMapBuilder.NoiseMap = heightMap;
            heightMapBuilder.SetSize(256, 256);
            heightMapBuilder.SetBounds(0.0f, 15.0f, 0.0f, 15.0f);
            heightMapBuilder.Seamless = true;
            heightMapBuilder.Build();

            for (int x = 0; x < Size; x++)
            {
                for (int y = 0; y < Size; y++)
                {
                    for (int z = 0; z < Size; z++)
                    {
                        blocksSolid[x, z, y] = (heightMap.GetValue(x, y) + 1) * Size / 2 < z ? dto.BlockType.Default : dto.BlockType.Air;
                    }
                }
            }
        }
    }
}
